var _common_util = require('util/common_util.js');

var _carousel_service = {

    cart : function(resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart'),
            success : resolve,
            error   : reject
        });
    },
    checkAll : function(resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/checkAll'),
            method  : 'PATCH',
            success : resolve,
            error   : reject
        });
    },
    unCheckAll : function(resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/unCheckAll'),
            method  : 'PATCH',
            success : resolve,
            error   : reject
        });
    },
    setQuantity : function (id, quantity, resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/' + id + '?action=updateNum&quantity=' + quantity),
            method  : 'PATCH',
            success : resolve,
            error   : reject
        });
    },
    getTotalPrice : function (resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/totalPrice'),
            method  : 'GET',
            success : resolve,
            error   : reject
        });
    },
    checkOne : function (id, resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/' + id + '?action=check'),
            method  : 'PATCH',
            success : resolve,
            error   : reject
        });
    },
    uncheckOne : function (id, resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/' + id + '?action=uncheck'),
            method  : 'PATCH',
            success : resolve,
            error   : reject
        });
    },
    deleteOne : function (id, resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/' + id),
            method  : 'DELETE',
            success : resolve,
            error   : reject
        })
    },
    getItemTotalPrice : function (id, resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/price/' + id),
            success : resolve,
            error   : reject
        })
    },
    addOne : function (id, resolve, reject) {
        var cart = {
            productId: id,
            quantity: 1,
            checked: 2,
            status: 1
        };
        _common_util.request({
            url         : _common_util.getServerURL('cart'),
            method      : 'POST',
            data        : JSON.stringify({
                            "productId": id,
                            "quantity": 1,
                            "checked": 2,
                            "status": 1
                        }),
            contentType :'application/json;charset=UTF-8',
            success     : resolve,
            error       : reject,
        });
    },
    getCheckedList : function (resolve, reject) {
        _common_util.request({
            url     : _common_util.getServerURL('cart/checked'),
            success : resolve,
            error   : reject
        })
    },

}

module.exports = _carousel_service